package com.shuxinxin.test.service.impl;

import com.shuxinxin.test.mapper.BookMapper;
import com.shuxinxin.test.mapper.UserMapper;
import com.shuxinxin.test.pojo.Book;
import com.shuxinxin.test.pojo.User;
import com.shuxinxin.test.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BookSerivceImpl implements BookService {

    @Autowired
    BookMapper bookMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<Book> queryBook(Book book) {
        return bookMapper.selectBook(book);
    }

    @Override
    public List<Map<String, Object>> queryAll() {

        return bookMapper.selectAll();
    }

//     修改图书信息
    @Override
    public int updateBook(Map map,Book book) {
//        查询是否为管理员
        String username = (String) map.get("username");
        System.out.println("sdaf"+"user"+username);
        User user = userMapper.selectManage(username);
        System.out.println(user);
        if(user.getAdmin() == 1) {

//            修改
            bookMapper.updateBook( book.getBook_writer() ,book.getBook_name(), book.getBook_type(), book.getBook_price(),book.getBook_id());
            return 1;
        }
        return 0;
    }
}
